package org.misty.seckill.redis;

public abstract class BaseKeyPrefix implements KeyPrefix {
  private final Class<?> model;
  private final int expiryInSec;
  private final String prefix;

  public BaseKeyPrefix(Class<?> model, int expiryInSec, String prefix) {
    this.model = model;
    this.expiryInSec = expiryInSec;
    this.prefix = prefix;
  }

  @Override
  public int getExpiryInSec() {
    return this.expiryInSec;
  }

  @Override
  public String getPrefix() {
    if (model != null) {
      var name = model.getSimpleName().toLowerCase();
      return name + ":" + prefix + ":";
    } else {
      return prefix + ":";
    }
  }
}
